<template>
	<view class="productDetail">
		<proDetailComponent ref="detailComponent" :productId="productId"></proDetailComponent>
	</view>
</template>

<script>
	import API from '@/common/api';
	import utils from '@/common/utils';
	import proDetailComponent from '@/pages/components/proDetailComponent.vue';
	export default {
		data() {
			return {
				productId: null,
				title: '玖玖优拼',
			};
		},
		components: {
			proDetailComponent
		},
		onHide() {
			if (this.$refs.detailComponent) {
				this.$refs.detailComponent.hide()
			}
		},
		onShow() {
			if (this.productId && this.$refs.detailComponent) {
				this.$refs.detailComponent.refresh()
				this.$refs.detailComponent.show()
			}
		},
		onLoad(e) {
			this.productId = e.productId;
		},
		onShareAppMessage() {
			return {
				title: this.title,
				imageUrl: this.shareCoverImage,
				path: '/pages/tabbar/homePage/index?scene=' + uni.getStorageSync('uid')
			}
		},
		onShareTimeline() {
			return {
				title: this.title,
				imageUrl: this.shareCoverImage,
				path: '/pages/tabbar/homePage/index?scene=' + uni.getStorageSync('uid')
			}
		},
		methods: {
			togglePopup(type) {
				this.type = type;
				console.log('弹框显示或关闭');
			},
			groupBtn() {
				const value = uni.getStorageSync('token');
				if (!value) {
					this.togglePopup('middle');
				} else {
					uni.navigateTo({
						url: './placeOrder?price=' + this.price + '&productId=' + this.productId
					});
				}
			},

			//获取用户信息
			loginWechat(callback) {
				uni.login({
					provider: 'weixin',
					success: loginRes => {
						console.log(loginRes, 'uni.login');
						uni.getUserInfo({
							provider: 'weixin',
							success: infoRes => {
								console.log(infoRes, 'getUserInfo')
								//1小程序登录 waLogin
								this.params.jsCode = loginRes.code;
								this.params.avatar = infoRes.userInfo.avatarUrl;
								this.params.gender = infoRes.userInfo.gender === 2 ? 'female' :
									'male';
								this.params.name = infoRes.userInfo.nickName;
								this.params.inviteUserId = uni.getStorageSync('inviteUserId');
								API.waLogin(this.params).then(res => {
									console.log(res, '登录成功');
									uni.setStorageSync('token', res.data.token);
									this.togglePopup('close');
								});
							}
						});
					}
				});
			},
			topSwiperTab(e) {
				var that = this;
				this.topSwiperIndex = Number(e.target.current);
			}
		}
	};
</script>

<style lang="less">
	.productDetail {}
</style>
